package com.hengxinguotong.hxgtwygsp.ui.notice;

import android.content.Intent;
import android.support.annotation.NonNull;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.hengxinguotong.hxgtwygsp.R;
import com.hengxinguotong.hxgtwygsp.model.Notice;
import com.hengxinguotong.hxgtwygsp.ui.base.BaseTabFragment;
import com.hengxinguotong.hxgtwygsp.ui.base.BaseViewHolder;
import com.hengxinguotong.hxgtwygsp.ui.web.WebActivity;
import com.hengxinguotong.hxgtwygsp.widget.RecycleViewDivider;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;

public class NoticeFragment extends BaseTabFragment
{
    @BindView(R.id.notice_recycler)
    RecyclerView noticeRecycler;

    private List<Notice> noticeList;
    private NoticeAdapter noticeAdapter;

    public NoticeFragment()
    {
    }

    @Override
    public int getLayoutResId()
    {
        return R.layout.fragment_notice;
    }

    @Override
    public void init()
    {
        noticeList = new ArrayList<>();
        for (int i = 0; i < 10; i++)
        {
            noticeList.add(new Notice());
        }
        LinearLayoutManager llm = new LinearLayoutManager(getContext());
        llm.setOrientation(LinearLayoutManager.VERTICAL);
        noticeRecycler.setLayoutManager(llm);
        noticeRecycler.addItemDecoration(new RecycleViewDivider(getContext()).color(R.color.c414C7B));
        noticeAdapter = new NoticeAdapter();
        noticeRecycler.setAdapter(noticeAdapter);
    }

    public class NoticeHolder extends BaseViewHolder<Notice>
    {
        @BindView(R.id.text_image)
        ImageView textImage;
        @BindView(R.id.text_date)
        TextView textDate;
        @BindView(R.id.text_title)
        TextView textTitle;
        @BindView(R.id.text_content)
        TextView textContent;

        public NoticeHolder(View itemView)
        {
            super(itemView);
            itemView.setOnClickListener(noticeAdapter);
        }

        @Override
        public void bindData(Notice notice)
        {

        }
    }

    public class NoticeAdapter extends RecyclerView.Adapter<NoticeHolder> implements View.OnClickListener
    {

        @NonNull
        @Override
        public NoticeHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType)
        {
            View view = View.inflate(getContext(), R.layout.item_notice, null);
            return new NoticeHolder(view);
        }

        @Override
        public void onBindViewHolder(@NonNull NoticeHolder holder, int position)
        {
            holder.bindData(noticeList.get(position));
        }

        @Override
        public int getItemCount()
        {
            return noticeList.size();
        }

        @Override
        public void onClick(View v)
        {
            Intent intent = new Intent(getContext(), WebActivity.class);
            startActivity(intent);
        }
    }
}
